//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lanf.system.code;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Utils {
    private static Pattern linePattern = Pattern.compile("_(\\w)");
    private static Pattern humpPattern = Pattern.compile("[A-Z]");

    public Utils() {
    }

    public static String dataToProperty(String columnType) {
        if (!"TINYINT".equalsIgnoreCase(columnType) && !"INT".equalsIgnoreCase(columnType) && columnType.indexOf("INT") <= -1 && columnType.indexOf("int") <= -1) {
            if (!"BIGINT".equalsIgnoreCase(columnType) && !"VARCHAR".equalsIgnoreCase(columnType) && !"CHAR".equalsIgnoreCase(columnType) && !"text".equalsIgnoreCase(columnType) && !"tinytext".equalsIgnoreCase(columnType)) {
                if (!"double".equalsIgnoreCase(columnType) && !"float".equalsIgnoreCase(columnType) && !"decimal".equalsIgnoreCase(columnType) && !"numeric".equalsIgnoreCase(columnType) && columnType.indexOf("DECIMAL") <= -1) {
                    if (!"DATETIME".equalsIgnoreCase(columnType) && !"timestamp".equalsIgnoreCase(columnType) && !"time".equalsIgnoreCase(columnType)) {
                        columnType = "String";
                    } else {
                        columnType = "java.util.Date";
                    }
                } else {
                    columnType = "java.math.BigDecimal";
                }
            } else {
                columnType = "String";
            }
        } else {
            columnType = "Integer";
        }

        return columnType;
    }

    public static String lineToHump(String str) {
        if (str == null) {
            return str;
        } else {
            str = str.toLowerCase();
            Matcher matcher = linePattern.matcher(str);
            StringBuffer sb = new StringBuffer();

            while(matcher.find()) {
                matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
            }

            matcher.appendTail(sb);
            return sb.toString();
        }
    }

    public static String humpToLine2(String str) {
        if (str == null) {
            return str;
        } else {
            Matcher matcher = humpPattern.matcher(str);
            StringBuffer sb = new StringBuffer();

            while(matcher.find()) {
                matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
            }

            matcher.appendTail(sb);
            return sb.toString();
        }
    }

    public static String toFirstUpper(String str) {
        return str != null && !"".equals(str) && str.length() > 0 ? str.substring(0, 1).toUpperCase() + (str.length() > 1 ? str.substring(1) : "") : "";
    }

    public static String toFirstLower(String str) {
        return str != null && !"".equals(str) && str.length() > 0 ? str.substring(0, 1).toLowerCase() + (str.length() > 1 ? str.substring(1) : "") : "";
    }

    public static void main(String[] args) {
        System.out.println(lineToHump("sys_dic_item"));
        String str2 = "{\"dicCode\":\"1000\"}";
    }
}
